#include <iostream>
using namespace std;
const int N = 1e6 + 10;

int e[N], ne[N], idx;

void init()
{
    ne[0] = -1;
    idx = 1;
}

void push_front(int x)
{
    e[idx] = x;
    ne[idx] = ne[0];
    ne[0] = idx;
    idx++;
}
void to_insert(int x , int k)
{
    e[idx] = x;
    ne[idx] = ne[k];
    ne[k] = idx;
    idx++;
}
void remove(int k)
{
    if(ne[0] != -1) ne[0] = ne[ne[0]];
}
void Print(){
    int i = ne[0];
    while(i != -1){
        std::cout << e[i] << " ";
        i = ne[i];
    }
    std::cout << std::endl;
}
void Memu()
{
    int n = -1;
    init();
    while (n)
    {
        std::cout << "--------------" << std::endl;
        std::cout << "0.退出" << std::endl;
        std::cout << "1.将val插入到k节点之后" << std::endl;
        std::cout << "2.头插" << std::endl;
        std::cout << "3.头删" << std::endl;
        std::cout << "4.查看链表" << std::endl;
        std::cout << "--------------" << std::endl;
        cin >> n;
        int val,k;
        if(n == 1)
        {
            std::cout << "val:";
            cin >> val;
            std::cout << "k:";
            cin >> k;
            to_insert(val,k);
        }else if(n == 2){
            std::cout << "val:";
            cin >> val;
            push_front(val);
        }else if(n == 3){
            remove(k);
        }else if(n == 4){
            Print();
        }
    }
}

int main()
{
    Memu();
    return 0;
}